<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title></title>
    <style>
        *{
            margin:0;
            padding: 0;
            list-style: none;
            border:0;
        }

        a{
            text-decoration: none;
            color: #000;
        }

        #nav{
            width: 900px;
            height: 40px;
            border: 1px solid #ccc;
            margin: 100px auto;
            overflow: hidden;
        }

        #nav ul{
            width: 910px;
        }

        #nav ul li{
            float: left;
            width: 100px;
            line-height: 40px;
            text-align: center;
            background: url("images/_r1_c1.png") no-repeat 0 0 ;
            border-right: 1px dashed #ccc;

            position: relative;
        }

        #nav ul li a{
            width: 100%;
            height: 100%;
            display: inline-block;
        }

        span{
            width: 100px;
            height: 40px;
            background-color: skyblue;
            position: absolute;
            left: 0;
            top: 40px;

            z-index:  -1;
        }
    </style>
</head>
<body>
    <nav id="nav">
        <ul id="ul">
            <li><a href="">首页</a><span></span><audio src="source/a1.mp3"></audio></li>
            <li><a href="">新头条</a><span></span><audio src="source/a2.mp3"></audio></li>
            <li><a href="">电视剧</a><span></span><audio src="source/a3.mp3"></audio></li>
            <li><a href="">新电影</a><span></span><audio src="source/a4.mp3"></audio></li>
            <li><a href="">小游戏</a><span></span><audio src="source/a5.mp3"></audio></li>
            <li><a href="">小说汇</a><span></span><audio src="source/a6.mp3"></audio></li>
            <li><a href="">旅游假</a><span></span><audio src="source/a7.mp3"></audio></li>
            <li><a href="">正品购</a><span></span><audio src="source/a8.mp3"></audio></li>
            <li><a href="">今日团</a><span></span><audio src="source/a9.mp3"></audio></li>
        </ul>
    </nav>
<script src="js/myFunc.js"></script>
<script>
    window.onload = function () {
        // 1. 获取标签
        var ul = $("ul");
        var allLis = ul.children;

        // 2. 改变背景
        for(var i=0; i<allLis.length; i++){
            allLis[i].style.backgroundPosition = '0 ' + i * -40 + 'px';
            // 2.1 监听鼠标进入
            allLis[i].onmouseover = function () {
                // 2.2 缓动动画
                buffer(this.children[1], {top: 0});

                // 2.3 播放音乐
                this.children[2].play();
                this.children[2].currentTime = 0;
        };

            // 2.2 监听鼠标离开
            allLis[i].onmouseout = function () {
                buffer(this.children[1], {top: 40});
            }
        }

        // 3. 监听键盘的点击
        document.onkeydown = function (event) {
             var e = event || window.event;
             // console.log(e.keyCode);
             var keyCode = e.keyCode - 49;
             buffer(allLis[keyCode].children[1], {top: 0}, function () {
                 buffer(allLis[keyCode].children[1], {top: 40});
             });

            // 3.1 播放音乐
            allLis[keyCode].children[2].play();
            allLis[keyCode].children[2].currentTime = 0;
        }
    }
</script>
</body>
</html>